﻿Ext.extend(demo.module,{
    init: function(){  
 	  var opt={ 
	  url:'newsquery'	  
	  };  	  
	  var type_data=[['1','our customers'],['2','silk rugs knowledge and info']];
	  opt.fields=[
	  {name:'id',text:'id',header:{hidden:true},ft:'hidden'},
	  {name:'title',text:'标题',ft:{allowBlank:false}},
	  {name:'shortdes',text:'简短概况',ft:{allowBlank:false}},
	  {name:'keywords',text:'关键字',ft:{allowBlank:false}},	 
	  {name:'seq',text:'权重',ft:{xtype:'numberfield',allowBlank:false,allowNegative:false,allowDecimals:false}},
	  {name:'ntype',text:'类型',ft:{		
	                        xtype:'combo',	                       
	                        hiddenName:'ntype',
	                        store: new Ext.data.SimpleStore({
							fields: ['_v','_t'],						
							data :type_data
							}),
							valueField:'_v',							
						    displayField: '_t',				
	                        mode: 'local',
	                        editable:false,
	                        triggerAction: 'all'	                       
	  },header:{renderer:function(v){
	      if(v){return type_data[v-1][1];}else{return "无类型";}
	  }}},
	  {name:'content',text:'内容',header:{hidden:true},ft:{xtype:'fieldset',layout:'fit',anchor:'100%',border:false,height:350,items:[{xtype:'fckeditor',name:'content',height: 340}]}}
	  ];
	  opt.windowConfig={width:850};	  
	  opt.gridConfig={};	
	  opt.gridConfig.tbar=[
	   {text:'添加',iconCls:'add',handler:function(x){
	     this.window.setTitle(x);
	     this.window.show();
	   }},
	   {
	     text:'修改',iconCls:'edit',handler:function(x)
	     {
	       this.window.setTitle(x);
	       this.edit();	 
	     }
	   },
	   {
	     text:'删除',iconCls:'delete',handler:function(x)
	     {	       
	       this.del(function(rs){
	         this.postJson({
	           url:'deletenews',
	           params:{news:{id:rs[0].get("id")}}
	         })
	       })
	     }
	   
	   }
	  ];  
     
     opt.gridConfig.bbar={pageSize:10};     
	 var g=new Ext.fay.ui.CURDGrid(opt);
	 g.on("save",function(values){
	    var bf=this.form.getForm();
	    values.content=bf.findField("content").getValue();
	    values.ntype=bf.findField("ntype").getValue();
	    if(this.isValid())
	    {
	      this.postJson({
	       url:'savenews',
	       params:{news:values}
	      })
	    }
	 });  
	 this.main.add(g.grid);
     this.main.doLayout();   
     g.ds.reload({params:{start:0,limit:10}});
   }
});